try:
  import json as simplejson
except ImportError:
  from django.utils import simplejson  # Fallback for Python 2.5 or earlier
  
import urllib
import urllib2

def query(fql, access_token = None):
  url_path = 'https://api.facebook.com/method/fql.query'
  params = {'format': 'json', 'query': fql}
  if access_token:
    params['token'] = access_token
    
  url = '%s?%s' % (url_path, urllib.urlencode(params))
  response = urllib2.urlopen(url)
  json_str = response.read()
  
  data = simplejson.loads(json_str)
  return data
  
  
    